from appium_practice.PO_MODE.page.basepage import CommonBasePage
from appium_practice.PO_MODE.page.mainpage import MainPage
from appium_practice.PO_MODE.until.helpers import ANDROID_BASE_CAPS, IOS_BASE_CAPS, EXECUTOR
from appium import webdriver


class APP(CommonBasePage):

    def start(self, platform):
        if self.appium_driver is None:
            if platform == 'ANDROID':
                self.appium_driver = webdriver.Remote(command_executor=EXECUTOR,
                                                      desired_capabilities=ANDROID_BASE_CAPS)
            elif platform == 'IOS':
                self.appium_driver = webdriver.Remote(command_executor=EXECUTOR,
                                                      desired_capabilities=IOS_BASE_CAPS)
            self.appium_driver.implicitly_wait(3)

        else:
            self.appium_driver.launch_app()
        return self

    def stop(self):
        self.appium_driver.quit()

    def restart(self):
        self.appium_driver.close_app()
        self.appium_driver.launch_app()

    def goto_main(self):
        return MainPage(self.appium_driver)